package com.balabala.config;

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * \* User: SuMaLi
 * \* Date: 2020/6/30
 * \* Time: 14:31
 * \
 */
public class RabbitConnectionUtils {

    /**
     * 获取MQ连接
     * @return
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //定义连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //设置链接地址
        connectionFactory.setHost("192.168.122.144");
        //端口
        connectionFactory.setPort(5672);
        //vhost 库名
        connectionFactory.setVirtualHost("/");
        //用户名
        connectionFactory.setUsername("SuMarry");
        //密码
        connectionFactory.setPassword("jt0817..");
        return connectionFactory.newConnection();
    }

}
